﻿///////////////////////////////////////////////////////////////
//                                                           //
// Code from Arcanea Project.                                //
//                                                           //
// Please include this license part to every reproduction    //
//   of code.                                                //
//                                                           //
// This code is under Ms-RL license                          //
//                                                           //
// Please read futher information about the license,         //
//   the project (news and updates) and the                  //
//   contributors on the address :                           //
//     http://www.codeplex.com/Arcanea/                      //
//                                                           //
///////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using Arcanea.NetworkEngine.Abstract.Engines;

namespace Arcanea.NetworkEngine.Concrete.Engines.Frame
{
    /// <summary>
    /// Engine de creation de trame TCP
    /// </summary>
    public class SimpleTCPFrameEngine : IFrameEngine
    {

        public override byte[] BuildFrame(byte[] arrayUnbuilded)
        {
            byte[] complement = BitConverter.GetBytes(arrayUnbuilded.Length);

            return FusionArray(complement, arrayUnbuilded);

        }

        public override byte[] UnbuildFrame(IProtocoleEngine engine)
        {
            byte[] length = engine.Receive(sizeInt);
            if (length == null) return null;

            int size = BitConverter.ToInt32(length,0);

            return engine.Receive(size);
        }
    }
}
